package com.itheima.controller;

import com.itheima.po.User;
import com.itheima.service.UserService;
import com.itheima.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/register")
    @ResponseBody
    public User register(@RequestBody  User user){
        System.out.println("注册用户信息：" + user);
        if(userService.createUser(user)==1){
            return user;
        }
        else {
            User user_error = new User();
            user_error.setUsername("none");
            return user_error;
        }
    }

    @RequestMapping("/login")
    @ResponseBody
    public User login(@RequestBody User user){
        System.out.println("用户登录：" + user);
        if(userService.userLogin(user)==1){
            return user;
        }
        else {
            User user_error = new User();
            user_error.setUsername("none");
            return user_error;
        }
    }


}
